package com.sservice.commonBusiness.controller.web;

import com.github.pagehelper.PageHelper;
import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.commonBusiness.e.Statistic;
import com.sservice.commonBusiness.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by byte_su@163.com on 2018/02/05.
 * 统计信息
 */
@Controller
@RequestMapping("/statistic1/")
public class Statistic1Controller {

    @Autowired
    public  StatisticService statisticService;



    @RequestMapping(value = "statistic", method = RequestMethod.GET)
    @ResponseBody
    public BaseResult statistic(Statistic statistic) {
        if (statistic.getTargetId() == null || statistic.getType1() == null) {
            return new BaseResult(false, "参数错误", 403);
        }

        statisticService.plus(statistic.getTargetId(), statistic.getType1(),
                statistic.getRemark() != null ? statistic.getRemark() : "view");
        return new BaseResult(true, "ok", 200);
    }

    /**
     * 设置字段值
     *
     * @param statistic
     * @return
     */
    @RequestMapping(value = "set", method = RequestMethod.GET)
    @ResponseBody
    public BaseResult set(Statistic statistic) {
        statisticService.setField(statistic);
        return new BaseResult(true, "ok", 200);
    }


    @RequestMapping("detail/{id}")
    @ResponseBody
    public BaseResult detail(@RequestParam Integer id) {
        Statistic statistic = statisticService.selectByPrimaryKey(id);
        return new BaseResult(true, statistic);
    }

    @RequestMapping("get")
    @ResponseBody
    public BaseResult getStatistic(Statistic statistic) {
        Statistic statistic1 = statisticService.selectBy(statistic.getTargetId(), statistic.getType1());
        return new BaseResult(true, statistic1);
    }

    @RequestMapping("list")
    @ResponseBody
    public ListResult list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
//        List<Statistic> list = statisticService.findAll();
//        PageInfo pageInfo = new PageInfo(list);
//        return new ListResult(true, pageInfo);
        return null;
    }
}
